﻿@using Covenant.Models.Covenant
@using Microsoft.AspNetCore.Identity
@inject UserManager<CovenantUser> UserManager
@inject SignInManager<CovenantUser> SignInManager
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="~/images/favicon.ico" type="image/x-icon">
    @if (!(SignInManager.UserManager.Users.Any() && SignInManager.IsSignedIn(User)))
    {
        ViewData["Title"] = "Login";
    }
    <title>Covenant - @ViewData["Title"]</title>

    <environment include="Development">
        <link rel="stylesheet" href="~/css/bootstrap.min.css" />
        <link rel="stylesheet" href="~/css/bootstrap-datetimepicker.min.css" />
        <link rel="stylesheet" href="~/css/bootstrap-select.min.css" />
        <link rel="stylesheet" href="~/css/bootstrap-multiselect.css" />
        <link rel="stylesheet" href="~/css/all.css" />
        <link rel="stylesheet" href="~/css/jquery.typeahead.min.css" />
        <link rel="stylesheet" href="~/css/datatables.min.css" />
        <link rel="stylesheet" href="~/css/dashboard.css" />
        <link rel="stylesheet" href="~/css/covenant.css" />
    </environment>
    <environment exclude="Development">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
              asp-fallback-href="~/css/bootstrap.min.css"
              asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute"
              integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
              crossorigin="anonymous">
        <link rel="stylesheet" href="~/css/bootstrap-datetimepicker.min.css" />
        <link rel="stylesheet" href="~/css/bootstrap-select.min.css" />
        <link rel="stylesheet" href="~/css/bootstrap-multiselect.css" />
        <link rel="stylesheet" href="~/css/all.css" />
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-typeahead/2.10.6/jquery.typeahead.min.css">
        <link rel="stylesheet" href="https://cdn.datatables.net/v/bs4/dt-1.10.18/datatables.min.css" />
        <link rel="stylesheet" href="~/css/dashboard.css" />
        <link rel="stylesheet" href="~/css/covenant.css" />
    </environment>
    @RenderSection("Sheets", required: false)
</head>
<body>
    @if (SignInManager.UserManager.Users.Any() && SignInManager.IsSignedIn(User))
    {
        <nav class="navbar navbar-expand navbar-dark sticky-top bg-dark">
            <a class="navbar-brand ml-3 align-items-center" href="/">
                <img src="~/images/covenant-white.png" alt="Covenant" height="28" width="101">
            </a>
            <ul class="navbar-nav ml-auto">
                @{
                    CovenantUser covuser = await UserManager.GetUserAsync(User);
                }
                @if (covuser != null)
                {
                    <li class="nav-item text-nowrap">
                        <a class="nav-link" asp-controller="CovenantUser" asp-action="Edit" asp-route-id="@covuser.Id">Welcome, @User.Identity.Name!</a>
                    </li>
                    <li class="nav-item text-nowrap">
                        <a class="nav-link" asp-controller="CovenantUser" asp-action="Logout">Logout</a>
                    </li>
                }
            </ul>
        </nav>
        <div class="toast" role="alert" aria-live="assertive" aria-atomic="true" style="position: absolute; top: 60px; right: 10px; z-index: 1;" data-delay="15000">
            <div class="toast-header">
                <strong class="mr-auto">Event</strong>
                <small>Now</small>
                <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="toast-body">
                Message
            </div>
        </div>
        <div id="covenant-container" class="container-fluid">
            <div class="d-flex flex-row">
                <nav class="col-sm-2 bg-light sidebar">
                    <div class="sidebar-sticky">
                        <ul class="nav flex-column">
                            <li class="nav-item">
                                <a asp-controller="Home" asp-action="Index" id="nav-dashboard" class="nav-link active">
                                    <span data-feather="home"></span>
                                    Dashboard
                                </a>
                            </li>
                            <li class="nav-item">
                                <a asp-controller="Listener" asp-action="Index" id="nav-listeners" class="nav-link">
                                    <span data-feather="headphones"></span>
                                    Listeners
                                </a>
                            </li>
                            <li class="nav-item">
                                <a asp-controller="Launcher" asp-action="Index" id="nav-launchers" class="nav-link">
                                    <span data-feather="zap"></span>
                                    Launchers
                                </a>
                            </li>
                            <li class="nav-item">
                                <a asp-controller="Grunt" asp-action="Index" id="nav-grunts" class="nav-link">
                                    <span data-feather="terminal"></span>
                                    Grunts
                                </a>
                            </li>
                            <li class="nav-item">
                                <a asp-controller="Template" asp-action="Index" id="nav-templates" class="nav-link">
                                    <span data-feather="code"></span>
                                    Templates
                                </a>
                            </li>
                            <li class="nav-item">
                                <a asp-controller="GruntTask" asp-action="Index" id="nav-tasks" class="nav-link">
                                    <span data-feather="package"></span>
                                    Tasks
                                </a>
                            </li>
                            <li class="nav-item">
                                <a asp-controller="GruntTasking" asp-action="Index" id="nav-taskings" class="nav-link">
                                    <span data-feather="layers"></span>
                                    Taskings
                                </a>
                            </li>
                            <li class="nav-item">
                                <a asp-controller="Graph" asp-action="Index" id="nav-graph" class="nav-link">
                                    <span data-feather="share-2"></span>
                                    Graph
                                </a>
                            </li>
                            <li class="nav-item">
                                <a asp-controller="Data" asp-action="Index" id="nav-data" class="nav-link">
                                    <span data-feather="database"></span>
                                    Data
                                </a>
                            </li>
                            <li class="nav-item">
                                <a asp-controller="CovenantUser" asp-action="Index" id="nav-users" class="nav-link">
                                    <span data-feather="users"></span>
                                    Users
                                </a>
                            </li>
                        </ul>
                    </div>
                </nav>

                <main role="main" class="col-sm-10 pt-3">
                    @RenderBody()
                </main>
            </div>
            <footer>
                <p></p>
            </footer>
        </div>
    }
    else
    {
        await Html.RenderPartialAsync("../CovenantUser/_LoginPartial", new CovenantUserRegister());
        IgnoreBody();
    }
    <environment include="Development">
        <script src="~/js/jquery.min.js"></script>
        <script src="~/js/popper.min.js"></script>
        <script src="~/js/bootstrap.min.js"></script>
        <script src="~/js/moment.min.js"></script>
        <script src="~/js/feather.min.js"></script>
        <script>feather.replace();</script>
        <script src="~/lib/signalr/dist/browser/signalr.js"></script>
        <script src="~/js/datatables.min.js"></script>
        <script src="~/js/bootstrap-select.min.js"></script>
        <script src="~/js/bootstrap-multiselect.js"></script>
    </environment>
    <environment exclude="Development">
        <script src="https://code.jquery.com/jquery-3.3.1.min.js"
                asp-fallback-src="~/js/jquery.min.js"
                asp-fallback-test="window.jQuery"
                crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
                integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
                crossorigin="anonymous"></script>
        <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
                asp-fallback-src="~/js/bootstrap.min.js"
                asp-fallback-test="window.jQuery && window.jQuery.fn && window.JQuery.fn.modal"
                integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
                crossorigin="anonymous"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.21.0/moment.min.js"
                type="text/javascript"></script>
        <script src="~/js/feather.min.js"></script>
        <script>feather.replace();</script>
        <script src="~/lib/signalr/dist/browser/signalr.js"></script>
        <script src="https://cdn.datatables.net/v/bs4/dt-1.10.18/datatables.min.js"
                type="text/javascript"></script>
        <script src="~/js/bootstrap-multiselect.js"></script>
        <script src="~/js/bootstrap-select.min.js"></script>
    </environment>
    <script type="text/javascript">
        $(document).ready(function () {
            var displayEvent = function (event) {
                var msg = event.messageHeader.substring(event.messageHeader.indexOf("UTC] ") + 5, event.messageHeader.length)
                $(".toast-body").text(msg);
                $(".toast").toast('show');
            }

            var connection = new signalR.HubConnectionBuilder().withUrl("/eventHub").build();

            connection.on("ReceiveEvent", displayEvent);

            connection.start()
                .then(function () {
                    connection.invoke("JoinGroup", "*").catch(function (err) {
                        return console.error(err.toString());
                    });
                });
        });
    </script>

    @RenderSection("Scripts", required: false)
</body>
</html>